<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<include file="Public/head" />
</head>

<body>
<include file="Public/top" />

<div class="page_minheight">
<div class="login_tit">
  <div class="return"><a href="{:U('User/forget_pwd')}"><i class="icon-fanhui"></i></a></div>
  <span>验证身份</span>
</div><!--login_tit-->

<div class="page_in margin">
  <select id="verify-type-selector" style="display:none;">
  <if condition="strstr($_POST['username'],'@')">
  <option value="email" selected alias-value="2">邮箱验证</option>
  <else / >
  <option value="phone" selected alias-value="1">手机验证</option>
  </if>
  </select>
  
  <if condition="$v_type1 eq 'phone'">
  <div class="ginput_div ginput_div_icon"><i class="icon-shouji1"></i><input class="ginput" type="text" name="mobile" id="mobile" onBlur="chkuser()" placeholder="已验证手机号码：{$userinfo.mobile}" readonly /><input type="hidden" id="mobile_c" value="{$userinfo.mobile}" /></div>
  <elseif condition="$v_type1 eq 'email'"/>
  <div class="ginput_div ginput_div_icon"><i class="icon-xinfeng"></i><input class="ginput" type="text" name="mobile" id="mobile" onBlur="chkuser()" placeholder="已验证邮箱：{$userinfo.email}" readonly/><input type="hidden" id="email_c" value="{$userinfo.email}" /></div>
  </if>
  
  <div class="ginput_div ginput_div_icon">
    <div class="fl"><i class="icon-yanzhengma2"></i><input class="ginput" name="tpcode" id="tpcode" type="text" placeholder="短信验证码" /></div>
    <div class="fr"><button type="button" class="reg_send" id="count_down1" onClick="send_sms_reg_code()">获取短信验证码</button></div>
    <div class="clear"></div>
  </div>
  <div class="ginput_div"><button type="submit" class="login_sub" onclick="setpwd()">下一步</button></div>
</div><!--page_in-->
</div><!--page_minheight-->

<script>
 // 发送手机短信
    function send_sms_reg_code(){
        var mobile = $('#mobile_c').val();
        var email = $('#email_c').val();
        var type = $('#verify-type-selector').val();

        if(!checkMobile(mobile)&&!checkEmail(email)){
            // layer.alert('请输入正确的手机号码', {icon: 2});// alert('请输入正确的手机号码');
            layer.alert('手机号码/邮箱不正确.', 800);
            return;
        }

        var url = "/index.php?m=Mobile&c=User&a=send_sms_reg_code";
//        var url = "{:U('Mobile/User/send_sms_code')}";

		$.ajax({
		  type:"post",
		  url:url,
		  data:{"mobile":mobile,"email":email,"type":type},
		  dataType:"json",
		  
		  success:function(data)
		  {

		      if(data.status!=1){
                  layer.alert(data.msg, 800);
                  return false;
              }
			  //发送成功
			  if(data.status=1)
			  {
				  counttime = "{$sms_time_out}"; // 手机短信超时时间
				  countdown('#count_down1',counttime);
			  }
		  }
		});
    }
	
	
	function countdown(divid,counttime)
	{
		$(divid).attr("disabled","disabled");
		$(divid).addClass("reg_send_off");
		
		counttime--;
        if(counttime<=-1)
        {
			$(divid).removeAttr("disabled");
			$(divid).removeClass("reg_send_off");
            $(divid).html("获取短信验证码");
            return false;
        }

        $(divid).html(counttime+'秒');

        setTimeout("countdown('"+divid+"',"+counttime+")",1000);
	}
	/*******************************/
	</script>
<script>
	countdown("#count_down1","{$stime}");
</script>


 <script>
function sendcode(o){
	$.ajax({
//		url:'/index.php?m=Mobile&c=User&a=send_validate_code&t='+Math.random(),
		url:'{:U("Mobile/User/sen_sms_code")}?t='+Math.random(),
		type:'post',
		dataType:'json',
		data:{type:$('#verify-type-selector').val(),send:$('#username').val()},
		success:function(res){
			if(res.status==1){
				timer(o);
			}else{
				layer.alert(res.msg, 800);
			}
		}
	})
}

var wait=180;
function timer(o) { 
	//$('span[data-tips-for="tpcode"]').find('i').addClass('icon');
	//$('span[data-tips-for="tpcode"]').find('i').removeClass('icon-warn');
	//$('span[data-tips-for="tpcode"]').find('.txt').empty();
    if (wait == 0) {  
        o.removeAttribute("disabled");            
        o.value="获取验证码";  
        wait = 180;  
    } else {  
        o.setAttribute("disabled", true);  
        o.value="重新发送(" + wait + ")";  
        wait--;  
        setTimeout(function() {  
          timer(o)  
        }, 1000)  
    }  
}

var is_check = false;
function checkcode(){
	var tpcode = $('#tpcode').val();
	//$('span[data-tips-for="tpcode"]').css('display','inline');
	//$('span[data-tips-for="tpcode"]').find('i').removeClass('icon');
	//$('span[data-tips-for="tpcode"]').find('i').addClass('icon-warn');
	if(tpcode == ''){
		//$('span[data-tips-for="tpcode"]').find('.txt').empty().html('验证码不能为空');
		
				layer.alert('验证码不能为空', 800);
		return;
	}
	if(tpcode.length != 4){
		//$('span[data-tips-for="tpcode"]').find('.txt').empty().html('验证码不正确');
				layer.alert('验证码不正确', 800);
		return;
	}
	
	$.ajax({
		url:'/index.php?m=Mobile&c=User&a=check_validate_code&t='+Math.random(),
		type:'post',
		dataType:'json',
		data:{code:tpcode,send:$('#username').val()},
		success:function(res){
			if(res.status==1){
				is_check = true;
				//$('span[data-tips-for="tpcode"]').css('display','inline');
				//$('span[data-tips-for="tpcode"]').find('i').removeClass('icon-warn');
				//$('span[data-tips-for="tpcode"]').find('i').addClass('icon-loss');
				//$('span[data-tips-for="tpcode"]').find('.txt').empty();
				window.location.href='/index.php?m=Mobile&c=User&a=set_pwd&t='+Math.random();
			}else{
				//$('span[data-tips-for="tpcode"]').find('.txt').empty().html(res.msg);
				layer.alert(res.msg, 800);
				//alert('验证码未验证通过');
				return false;				
			}
		}
	})
}

function setpwd(){


	var tpcode = $('#tpcode').val();

	//$('span[data-tips-for="tpcode"]').css('display','inline');
	//$('span[data-tips-for="tpcode"]').find('i').removeClass('icon');
	//$('span[data-tips-for="tpcode"]').find('i').addClass('icon-warn');
	if(tpcode == ''){
		//$('span[data-tips-for="tpcode"]').find('.txt').empty().html('验证码不能为空');
		layer.alert('验证码不能为空', 800);
		return;
	}
	if(tpcode.length != 4){
		//$('span[data-tips-for="tpcode"]').find('.txt').empty().html('验证码不正确');
		layer.alert('验证码不正确', 800);
		return;
	}

	checkcode();
 
}
</script>

<include file="Public/footer" />
<script src="__STATIC__/js/global_after.js" type="text/javascript"></script>
</body>
</html>